/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mediate;

import thread.Server_Thread;
import ucm.BasicInfo_UC;
import ucm.CheckRight_UC;
import ucm.ClientQuit;
import ucm.DeleteValue;
import ucm.NewAchievement;
import ucm.NewBookBorrower;
import ucm.NewCourse;
import ucm.SearchBook;
import ucm.SearchInfo;
import ucm.UpdateCard;
/**
 *
 * @author 马凯
 */

public class Mediate {
    private static Mediate instance;
    private String msg;
    private String output;
    private Server_Thread st;
    
    public Mediate(){

    }
    
    public static Mediate getInstance(String msg, Server_Thread st){
        if(instance==null){
            instance = new Mediate();
            instance.msg = msg;
            instance.st = st;
        }else{
            instance.st = st;
            instance.msg = msg;
        }
        return instance;
    }
    
    public String run(){
        System.out.println(msg);
        String[] code = msg.split(";");
        switch(Integer.valueOf(code[code.length-1])){
            case 1: System.out.println("CASE 1");SearchInfo.getInstance(msg, st).searchStudent();break;
            case 2: System.out.println("CASE 2");output = NewAchievement.getInstance(msg).run();break;
            case 3: System.out.println("CASE 3");output = NewCourse.getInstance(msg).run();break;
            case 4: System.out.println("CASE 4");output = CheckRight_UC.getInstance(msg).run();break;
            case 5: System.out.println("CASE 5");output = DeleteValue.getInstance(msg).deleteAchivement();break;
            case 6: System.out.println("CASE 6");SearchInfo.getInstance(msg, st).searchTeacher();break;
            case 7: System.out.println("CASE 7");output = DeleteValue.getInstance(msg).deleteCourse();break;
            case 8: System.out.println("CASE 8");output = BasicInfo_UC.getInstance(msg).run();break;
            case 9: System.out.println("CASE 9");output = SearchBook.getInstance(msg).run();break;
            case 10: System.out.println("CASE 10");output = NewBookBorrower.getInstance(msg).run();break;
            case 11: System.out.println("CASE 11");output = UpdateCard.getInstance(msg).modifyRFID();break;
            case 12: System.out.println("CASE 12");break;
            case 13: System.out.println("CASE 13");break;
            case 14: System.out.println("CASE 14");break;
            case 15: System.out.println("CASE 15");break;
            case 16: System.out.println("CASE 16");break;
            case 17: System.out.println("CASE 17");break;
            case 99: System.out.println("CASE exit");ClientQuit.getInstance(st).run();break;
//            case 7: output = StaffInfo_UC.getInstance(msg).run();break;
            default: output = "!!!!"; break;
        }
        return output;
    }
}
